<template>
  <div class="container">
    <div class="containers">
      <div class="containers-left">
        <div class="area">
          <span class="iconfont">&#xe65e;</span>
          <span class="where">{{this.locations.city}}</span>
          <span @click="changeCity" class="changeCity">切换城市</span>
          <span class="place">[&nbsp;三河&nbsp;香河&nbsp;廊坊&nbsp;]</span>
        </div>
        <div v-show="!username">
          <span @click="jumpLogin" class="login">立即登录</span>
          <span @click="jumpRegister" class="register">注册</span>
        </div>
        <div v-show="username">
          <span class="user">{{username}}</span>，
          <span @click="logout" class="logout">退出</span>
        </div>
      </div>
      <ul class="containers-right">
        <li @mouseenter="enterMyMeiTuan">我的美团</li>
        <li>手机APP</li>
        <li @mouseenter="enterBusinessCenter">商家中心</li>
        <li @mouseenter="enterMeiTuanRule">美团规则</li>
        <li @mouseenter="enterWebsiteNavigation">网站导航</li>
      </ul>
      <ul @mouseleave="leaveMyMeiTuan" v-show="showMyMeiTuan" class="ul">
        <li v-for="item of listOne" :key="item.id">{{item.content}}</li>
      </ul>
      <ul v-show="showBusinessCenter" @mouseleave="leaveBusinessCenter" class="ul-two">
        <li v-for="item of listTwo" :key="item.id">{{item.content}}</li>
      </ul>
      <ul v-show="showMeiTuanRule" @mouseleave="leaveMeiTuanRule" class="ul-three">
        <li v-for="item of listThree" :key="item.id">{{item.content}}</li>
      </ul>
      <ul v-show="showWebsiteNavigation" @mouseleave="leaveWebsiteNavigation" class="ul-four">
        <li>网站导航</li>
        <li>
          <div class="dl-one">
            <span class="title">酒店旅游</span>
            <div>
              <span>国际机票</span>
              <span>火车票</span>
              <span>民宿</span>
              <span>经济型酒店</span>
              <span>主题型酒店</span>
              <span>商务酒店</span>
              <span>公寓</span>
              <span>豪华酒店</span>
              <span>客栈</span>
              <span>青年旅社</span>
              <span>度假酒店</span>
              <span>别墅</span>
              <span>农家院</span>
            </div>
          </div>
          <div class="dl-two">
            <span class="title">吃美食</span>
            <div>
              <span>烤鱼</span>
              <span>特色小吃</span>
              <span>烧烤</span>
              <span>自助餐</span>
              <span>火锅</span>
              <span>代金券</span>
            </div>
          </div>
          <div class="dl-three">
            <span class="title">看电影</span>
            <div>
              <span>热映电影</span>
              <span>热门影院</span>
              <span>热映电影口碑榜</span>
              <span>最受期待电影</span>
              <span>国内票房榜</span>
              <span>北美票房榜</span>
              <span>电影排行榜</span>
            </div>
          </div>
          <div class="dl-four">
            <span class="title">手机应用</span>
            <div>
              <img src="//s0.meituan.net/bs/fe-web-meituan/2d53095/img/appicons/meituan.png" alt="">
              <img src="//s1.meituan.net/bs/fe-web-meituan/404d350/img/appicons/waimai.png" alt="">
              <img src="https://p0.meituan.net/travelcube/162c3308d9622f6d9cfaa49e60be4dca8573.png" alt="">
              <img src="//s1.meituan.net/bs/fe-web-meituan/404d350/img/appicons/dianping.png" alt="">
              <img src="//s1.meituan.net/bs/fe-web-meituan/404d350/img/appicons/maoyan.png" alt="">
            </div>
          </div>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
import { mapState } from 'vuex'
export default {
  name: 'CommonHeader',
  data() {
    return {
      /** 是否展示网站导航的hover列表 */
      showWebsiteNavigation: false,
      /** 是否展示美团规则的hover列表 */
      showMeiTuanRule: false,
      /** 是否展示我的美团的hover列表 */
      showMyMeiTuan: false,
      /** 是否展示商家中心的hover列表 */
      showBusinessCenter: false,
    }
  },
  props: {
    listOne: {
      type: Array,
      default() {
        return []
      }
    },
    listTwo: {
      type: Array,
      default() {
        return []
      }
    },
    listThree: {
      type: Array,
      default() {
        return []
      }
    }
  },
  methods: {
    /** 切换城市 */
    changeCity() {
      this.$router.push('/changeCity')
    },
    /** 登出 */
    logout() {
      this.$emit('logout')
    },
    /** 跳转到注册 */
    jumpRegister() {
      this.$router.push('/register')
    },
    /** 跳转到登录 */
    jumpLogin() {
      this.$router.push('/login')
    },
    /** 移出网站导航 */
    leaveWebsiteNavigation() {
      this.showWebsiteNavigation = false
    },
    /** 移入网站导航 */
    enterWebsiteNavigation() {
      this.showWebsiteNavigation = true
    },
    /** 移出美团规则 */
    leaveMeiTuanRule() {
      this.showMeiTuanRule = false
    },
    /** 移入美团规则 */
    enterMeiTuanRule() {
      this.showMeiTuanRule = true
    },
    /** 移入商家中心 */
    enterBusinessCenter() {
      this.showBusinessCenter = true
    },
    /** 移出商家中心 */
    leaveBusinessCenter() {
      this.showBusinessCenter = false
    },
    /** 移入我的美团 */
    enterMyMeiTuan() {
      this.showMyMeiTuan = true
    },
    /** 鼠标移出我的美团 */
    leaveMyMeiTuan() {
      this.showMyMeiTuan = false
    }
  },
  computed: {
    ...mapState(['username', 'locations'])
  }
}
</script>

<style lang="scss" scoped>
.container {
  background: #F8F8F8;
  width: 100%;
  font-size: 12px;
  color: #999;
  height: 40px;
  .containers {
    width: 1199px;
    margin: 0 auto;
    position: relative;
    display: flex;
    justify-content: space-between;
    &-left {
      display: flex;
      align-items: center;
      .area {
        margin-right: 20px;
        .iconfont {
          color: #999;
          font-size: 15px;
          padding-top: 1px;
        }
        .where {
          color: #666;
        }
        .changeCity {
          background: #F4F4F4;
          border: 1px solid #E5E5E5;
          border-radius: 2px;
          color: #666;
          margin: 0 4px;
          padding: 0 2px;
          cursor: pointer;
          &:hover {
            color: #FE8C00;
          }
        }
      }
      line-height: 40px;
      .login {
        cursor: pointer;
        color: #FE8C00;
        margin-right: 5px;
      }
      .register {
        cursor: pointer;
        &:hover {
          color: #FE8C00;
        }
      }
      .user {
        @extend .login;
      }
      .logout {
        @extend .register;
      }
    }
    &-right {
      display: flex;
      z-index: 101;
      li {
        height: 40px;
        text-align: center;
        padding: 12px 14px;
        box-sizing: border-box;
        border-left: 1px solid transparent;
        border-right: 1px solid transparent;
        cursor: pointer;
        &:hover {
          color: #FE8C00;
        }
        
      }
    }
    .ul {
      @extend .containers-right;
      flex-direction: column;
      position: absolute;
      top: 0;
      right: 324px;
      li {
        background-color: #fff;
        border-color: #E5E5E5;
        box-shadow: 0 3px 5px 0 rgba(0,0,0,0.1);
        box-sizing: border-box;
        width: 82px;
      }
    }
    .ul-two {
      @extend .ul;
      align-items: flex-end;
      right: 159px;
      li {
        width: 134px;
        &:nth-child(1) {
          width: 92px;
          border-right: 1px solid #E5E5E5;
          border-left: 1px solid #E5E5E5;
        }
      }
    }
    .ul-three {
      @extend .ul-two;
      right: 75.5px;
      li {
        width: 95px; 
        &:nth-child(1) {
          width: 95px;
        }
      }
    }
    .ul-four {
      right: 1px;
      display: flex;
      flex-direction: column;
      position: absolute;
      z-index: 101;
      top: 0;
      align-items: flex-end;
      li {
        height: auto;
        text-align: center;
        padding: 12px 14px;
        box-sizing: border-box;
        background-color: #fff;
        border-color: #E5E5E5;
        box-shadow: 0 3px 5px 0 rgba(0,0,0,0.1);
        cursor: pointer;
        &:nth-child(2) {
          width: 1199px;
          box-sizing: border-box;
          border-top-left-radius: 4px;
          padding: 30px 36px 65px 47px;
          display: flex;
          .dl-one {
            width: 285px;
            .title {
              text-align: center;
              display: inline-block;
              color: #000;
              font-size: 16px;
              margin-bottom: 30px;
              &:hover {
                color: #000;
              }
            }
            span {
              width: 92px;
              margin-top: 10px;
              &:hover {
                color: #FE8C00;
              }
            }
            div {
              display: flex;
              flex-wrap: wrap;
            }
          }
          .dl-two {
            @extend .dl-one;
            width: 184px;
            margin-left: 20px;
          }
          .dl-three {
            @extend .dl-two;
            width: 92px;
            margin-left: 55px;
          }
          .dl-four {
            @extend .dl-two;
            margin-left: 90px;
            width: auto;
            .title {
              margin-bottom: 40px;
            }
            div {
              display: flex;
              img {
                width: 65px;
                height: 65px;
                margin-left: 20px;
                &:nth-child(1) {
                  margin-left: 0;
                }
              }
            }
          }
        } 
      }
    }
  }
}
</style>